package com.okq.dao;

import com.okq.dao.base.Impl.BaseDao;
import com.okq.entity.Order;
import com.okq.util.page.Page;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 描述 : 订单Dao 作者 : zdl 日期 : 2017/6/29 15:26
 */
@Repository
public class OrderDao extends BaseDao {
	public void saveOrder(Order order) {
		super.save(order);
	}

	/*
	 * 删除订单记录
	 */
	public void deleteOrder(Order order) {
		super.delete(order);
	}

	/*
	 * 更新订单记录
	 */
	public void updateOrder(Order order) {
		super.update(order);
	}

	public void saveOrUpdateOrder(Order order) {
		super.saveOrUpdate(order);
	}

	public Order getOrderById(String id) {
		return (Order) super.get(Order.class, id);
	}

	public List<Order> listAllOrder() {
		String hql = "FROM Order WHERE isDelete = 0";
		return super.find(hql);
	}

	public Page<Order> pageByOrder(Page<Order> page, Order order) {
		StringBuilder hqlSb = new StringBuilder();
		hqlSb.append("FROM Order o WHERE o.isDelete = 0 ");
	/*	if (order != null) {
			Map<String, Object> param = new HashMap<>();
			// 按客户名称
			String customerId = order.getCustomerId();
			if (StringUtils.isNotBlank(customerId)) {
				hqlSb.append(" AND o.customerId LIKE ?2 ");
				param.put("2", "%" + customerId + "%");
			}
			hqlSb.append(" ORDER BY o.createTime DESC ");
			return super.findByPage(page, hqlSb.toString(), param);
		} else {*/
//			hqlSb.append(" ORDER BY o.createTime DESC ");
			return super.findByPage(page, hqlSb.toString(), null);
		}
/*	}
*/
	/**
	 * 根据客户关键字查询订单
	 * 
	 * @param customerKeyWord
	 *            客户关键字
	 * @return Order
	 */
	public Order getCustomerKeyWord(String customerKeyWord) {
		/*
		 * if(StringUtils.isNotBlank(customerKeyWord)){ String
		 * hql="FROM Order WHERE isDelete = 0 AND customerKeyWord = '" +
		 * customerKeyWord + "' "; return (Order) super.get(hql); }
		 */
		return null;
	}

}
